/*
* 外院转入人次
* */

$(function () {

    let myChart = echarts.init(document.getElementById("wqChart"));
    let option = {
        color: ['#3398DB'],
        tooltip: {
            trigger: 'axis',
            axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        grid: {
            top: 20,
            bottom:30,
            right:20,
            // containLabel: true
        },
        xAxis: [
            {
                type: 'category',
                data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
                axisTick: {
                    alignWithLabel: true
                },
                axisLabel: {
                    fontSize: 12,
                    color: "#b0c2f9",
                    interval:0,//横轴信息全部显示
                    rotate:-30,//-30度角倾斜显示
                }
            }
        ],
        yAxis: [
            {
                type: 'value',
                axisLabel: {
                    fontSize: 12,
                    color: "#b0c2f9"
                }
            }
        ],
        series: [
            {
                type: 'bar',
                barWidth: '60%',
                data: [ 420, 932, 601, 934, 1190, 1530, 1203, 820, 932, 901, 934, 790 ],
                itemStyle: {
                    normal: {
                        color: new echarts.graphic.LinearGradient(
                            0, 0, 0, 1,
                            [
                                {offset: 0, color: '#b0c2f9'},
                                {offset: 0.5, color: '#188df0'},
                                {offset: 1, color: '#185bff'}
                            ]
                        )
                    }
                }
            }
        ]
    };

    if (option && typeof option === "object") {
        myChart.setOption(option, true);
    }

    $.ajax({
        url: "/hospital/total/superior",
        dataType: "json"
    }).done(function(data) {
        // console.log('Data: ', data);
        const xData = [];
        for(let i in data.result) {
            xData.push(data.result[i].count);
        }
        myChart.setOption({
            series: [{
                data: xData
            }]
        });
    }).fail(function(jqXHR) {
        console.log("Ajax Fail: ", jqXHR.status, jqXHR.statusText);
    });


    //浏览器窗口大小变化时，重置报表大小
    $(window).resize(function() {
        myChart.resize();
    });

});